export function addWatermark(fileUrl, canvasId, canvasWidth, canvasHeight) { //添加水印
	return new Promise((resolve, reject) => {
		//水印文字样式相关
		let fontSize = 18; //水印字体大小
		let maskText = '北星掼牌'; //水印文字
		let fontColor = "rgba(255,255,255,.5)"; //水印颜色
		let lineHeight = 60; //水印文字行高
		let textWidth = 180; //水印文字宽度
		let diagonalLength = canvasHeight > canvasWidth ? canvasHeight * 2 :
			canvasWidth; //选取最长边
		// 保证水印文字范围是矩形最长边的2倍
		let ctx = wx.createCanvasContext(canvasId);
		ctx.drawImage(fileUrl, 0, 0, canvasWidth, canvasHeight) //在画布上绘入图片宽高等于canvas宽高
		ctx.translate(canvasWidth / 2, -diagonalLength);
		ctx.rotate(45 * Math.PI / 180); //设置文字的旋转角度，角度为45°；
		// 横向循环次数
		let crossTime = Math.ceil(diagonalLength * 2 / textWidth);
		// 竖向循环次数
		let verticalTime = Math.ceil(diagonalLength * 2 / lineHeight);
		for (let j = 0; j < verticalTime; j++) { //纵向循环
			ctx.setFontSize(fontSize);
			ctx.setFillStyle(fontColor);
			ctx.fillText(maskText, 0, lineHeight * j);
			for (let i = 1; i < crossTime; i++) { //横向循环
				ctx.setFontSize(fontSize);
				ctx.setFillStyle(fontColor);
				ctx.fillText(maskText, textWidth * i, lineHeight * j);
			}
		};
		ctx.draw(false, () => {
			uni.canvasToTempFilePath({
				width: canvasWidth,
				height: canvasHeight,
				canvasId: canvasId,
				// fileType: "jpg",
				success: (res) => {
					resolve(res.tempFilePath)
				},
				fail: (error) => {
					reject(error)
					console.error('Failed to save canvas:', error);
				},
			});
		});
	});
}
export function getImageInfo(fileUrl) {
	return new Promise((resolve, reject) => {
		uni.getImageInfo({
			src: fileUrl,
			fail: (error) => {}, // 替换为你的图片路径
			success: async (res) => {
				resolve({
					width: res.width,
					height: res.height
				})
			},
			flail: (error) => {
				reject(error)
			}
		});
	});
}